import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    baseUrl: "https://shslqxh.1meeting.com/", // 默认前端地址
    baseAPIUrl: "https://shslqxh.1meeting.com/api", // 默认后端地址
    // 基本信息
    loginToken: JSON.parse(localStorage.getItem("TEAM_LOGIN_TOKEN")) || "", // 登录验证token
    loginUserId: JSON.parse(localStorage.getItem("TEAM_LOGIN_USERID")) || "", // 登录用户id
    loginUserName:
      JSON.parse(localStorage.getItem("TEAM_LOGIN_USER_NAME")) || "", // 登录用户名
    levelList: JSON.parse(localStorage.getItem("LEVELLIST")) || [], // 考试等级列表

    // 用户提交报名已选信息
    checkedGradeId:
      JSON.parse(localStorage.getItem("TEAM_CHECKED_GRADEID")) || "", // 当前已选考试等级id
    checkedEnrollId:
      JSON.parse(localStorage.getItem("TEAM_CHECKED_ENROLLID")) || "", // 当前已选考试id
    examineeInforList:
      JSON.parse(localStorage.getItem("TEAM_EXAMINEEINFOR_LIST")) || [], // 已选考生列表

    // 页面缓存信息
    editExamineeId:
      JSON.parse(localStorage.getItem("TEAM_EDIT_EXAMINEE_ID")) || "", // 当前编辑考生id
    editExamineeKey:
      JSON.parse(localStorage.getItem("TEAM_EDIT_EXAMINEE_KEY")) || "1", // 是否编辑考生 1.是2.否
    watchOrderId: JSON.parse(localStorage.getItem("TEAM_WATCH_ORDERID")) || "", // 当前查看订单id
    watchOrderWay:
      JSON.parse(localStorage.getItem("TEAM_WATCH_ORDERWAY")) || "", // 当前查看订单来源
    watchEnrollId:
      JSON.parse(localStorage.getItem("TEAM_WATCH_ENROLLID")) || "", // 当前查看报名id
  },
  mutations: {
    // 更新token
    set_loginToken(state, value) {
      state.loginToken = value;
      if (value != "") {
        localStorage.setItem("TEAM_LOGIN_TOKEN", JSON.stringify(value));
      } else {
        localStorage.removeItem("TEAM_LOGIN_TOKEN");
      }
    },
    // 更新登录id
    set_loginUserId(state, value) {
      state.loginUserId = value;
      if (value != "") {
        localStorage.setItem("TEAM_LOGIN_USERID", JSON.stringify(value));
      } else {
        localStorage.removeItem("TEAM_LOGIN_USERID");
      }
    },
    // 更新登录用户名
    set_loginUserName(state, value) {
      state.loginUserName = value;
      if (value != "") {
        localStorage.setItem("TEAM_LOGIN_USER_NAME", JSON.stringify(value));
      } else {
        localStorage.removeItem("TEAM_LOGIN_USER_NAME");
      }
    },
    // 更新考试等级列表
    set_levelList(state, value) {
      state.levelList = value;
      localStorage.setItem("LEVELLIST", JSON.stringify(value));
    },

    // 更新已选考试等级id
    set_checkedGradeId(state, value) {
      state.checkedGradeId = value;
      localStorage.setItem("TEAM_CHECKED_GRADEID", JSON.stringify(value));
    },
    // 更新已选考试等级id
    set_checkedEnrollId(state, value) {
      state.checkedEnrollId = value;
      localStorage.setItem("TEAM_CHECKED_ENROLLID", JSON.stringify(value));
    },
    // 更新已选考生列表
    set_examineeInforList(state, value) {
      state.examineeInforList = value;
      localStorage.setItem("TEAM_EXAMINEEINFOR_LIST", JSON.stringify(value));
    },

    // 设置当前编辑考生id
    set_editExamineeId(state, value) {
      state.editExamineeId = value;
      localStorage.setItem("TEAM_EDIT_EXAMINEE_ID", JSON.stringify(value));
    },
    // 设置是否编辑考生
    set_editExamineeKey(state, value) {
      state.editExamineeKey = value;
      localStorage.setItem("TEAM_EDIT_EXAMINEE_KEY", JSON.stringify(value));
    },
    // 设置当前查看订单id
    set_watchOrderId(state, value) {
      state.watchOrderId = value;
      localStorage.setItem("TEAM_WATCH_ORDERID", JSON.stringify(value));
    },
    // 设置当前查看订单来源
    set_watchOrderWay(state, value) {
      state.watchOrderWay = value;
      localStorage.setItem("TEAM_WATCH_ORDERWAY", JSON.stringify(value));
    },
    // 设置当前查看报名id
    set_watchEnrollId(state, value) {
      state.watchEnrollId = value;
      localStorage.setItem("TEAM_WATCH_ENROLLID", JSON.stringify(value));
    },
  },
  actions: {},
  modules: {},
});
